// 相关流程数据
const Mock = require('mockjs')
const notice = Mock.mock({
  // 流程信息
  "taskData|20": [{
    // "oderNumber|+1":"1", //序号
    taskId: "@increment(100000,999999)", //任务编号
    'taskName|1': ["请假申请", "补卡申请", "绩效申请"], //任务名称
    fafMonth: "@date(yyyy-MM)", //发放月份
    'taskType|1': ["绩效预发", "绩效清算"], //任务类别
    startTime: "@date(yyyy/MM/dd)",
    result: "2022年10月绩效工资清算",
    'approveStatus|1': ['创建中', '待审批', '审批中', '审批驳回', '审批通过', '已办结', '已作废'], //状态 
    'OriginateAgency|1': ["说的就是", "东方红东方红"]
  }]
})
module.exports = [
  // 流程信息
  {
    url: '/vue-element-admin/task/list',
    type: 'post',
    response: config => {
      // const body = config.body
      console.log(config.body)
      const {
        taskId,
        taskName,
        taskType,
        fafMonth,
        startTime,
        approveStatus,
        pageNum,
        pageSize,
        OriginateAgency
      } = config.body
      var searchDataList = []
      var searchKeyList = []
      if (approveStatus === '全部') {
        searchDataList = notice.taskData
      } else {
        for (let i = 0; i < notice.taskData.length; i++) {
          if (notice.taskData[i].approveStatus === approveStatus) {
            searchDataList.push(notice.taskData[i]);
          }
        }
      }
      searchKeyList = searchDataList.filter(item => {
        let flag = true
        if (taskName && item.taskName.indexOf(taskName) === -1) {
          flag = false
        }

        if (OriginateAgency && item.OriginateAgency.indexOf(OriginateAgency) === -1) {
          flag = false
        }
        return flag
      })
      console.log(searchKeyList)
      // 数据整理
      var [index, size, total] = [pageNum, pageSize, searchKeyList.length]
      var len = total / size
      var totalPages = len - parseInt(len) > 0 ? parseInt(len) + 1 : len
      var newDataList = searchKeyList.slice((index - 1) * size, index * size)


      return {
        code: 20000,
        data: {
          pagenum: index,
          pagesize: size,
          content: newDataList,
          total: total,
          totalPages: totalPages,

        }
      }
    }
  },
  // 获取单个流程数据
  {
    url: '/vue-element-admin/task/getData',
    type: 'post',
    response: config => {
      const {
        Id
      } = config.body
      for (const process of notice.taskData) {
        if (process.taskId === Id) {
          return {
            code: 20000,
            data: process
          }
        }
      }

    }
  },
  // 编辑
  // 编辑数据
  {
    url: '/vue-element-admin/task/editData',
    type: 'post',
    response: config => {
      console.log(config.body)
      const body = config.body
      var index = notice.taskData.findIndex((item) => {
        return item.taskId === body.taskId
      });
      notice.taskData.splice(index, 1, Mock.mock({
        taskId: body.taskId,
        taskName: body.taskName,
        taskType: body.taskType,
        fafMonth: body.fafMonth,
        startTime: body.startTime,
        approveStatus: body.approveStatus,
        result: body.result
      }))
      return {
        code: 20000,
        msg: "编辑成功",
        data: {
          content: notice.taskData,
          total: notice.taskData.length,
        }
      }
    }
  },
  // 通知模块删除数据
  {
    url: '/vue-element-admin/task/dellist',
    type: 'post',
    response: config => {
      console.log(config.body)
      const body = config.body
      const index = notice.taskData.findIndex((item) => {
        return item.taskId === body.id
      });
      console.log("执行了")
      notice.taskData.splice(index, 1)
      console.log(index)
      return {
        code: 20000,
        msg: "删除成功",
        data: {
          content: notice,
          // total: notice.newsList.length,
        }
      }
    }
  },
]
